import { request } from '@umijs/max';
import { FileDetail, PageResponse } from './index';
import { SourceEntity } from './index';
// 音乐详情信息
export interface MusicInfoDetail {
    id?: number;
    name: string;
    album: string;
    cover: FileDetail;
    releaseDate: string;
    famousPersonId: number;
    genre: string;
    description: string;
    musicSourceInfo: SourceEntity[];
}

// 音乐分页查询请求
export interface MusicInfoPageRequest {
    pageCurrent: number;
    pageSize: number;
    keyword?: string;
    famousPersonId: number;
}

// 新增音乐信息实体
export interface MusicInfoAddRequest {
    name: string;
    album: string;
    releaseDate: string | null;
    genre: string;
    description: string;
    coverId: number | null;
    musicSourceInfo: SourceEntity[];
    famousPersonId: number;
}

// 更新音乐信息实体
export interface MusicInfoUpdateRequest extends MusicInfoAddRequest {
    id: number;
}

// 新增音乐信息
export async function addMusicInfo(data: MusicInfoAddRequest) {
    return request('/music-info/back', {
        method: 'POST',
        data,
    });
}

// 更新音乐信息
export async function updateMusicInfo(data: MusicInfoUpdateRequest) {
    return request('/music-info/back', {
        method: 'PUT',
        data,
    });
}

// 删除音乐信息
export async function deleteMusicInfo(idList: number[]) {
    const ids = idList.join(',');
    return request(`/music-info/back/${ids}`, {
        method: 'DELETE',
    });
}

// 分页查询
export async function getMusicInfoPage(pageRequest: MusicInfoPageRequest) {
    return request<PageResponse<MusicInfoDetail>>('/music-info/page', {
        method: 'POST',
        data: pageRequest,
    });
}

// 获取音乐详情
export async function getMusicInfoDetail(id: number) {
    return request<MusicInfoDetail>(`/music-info/${id}`, {
        method: 'GET',
    });
}
